#include "svpwm.h"

/*!
    \brief      SVPWM
    \param[in]  
    \param[out] 
    \retval
 */
 
void SVPWM_Run(SVGEN *v)
{
    v->tmp1 = v->Ubeta;
    v->tmp2 = (v->Ubeta*16384 + v->Ualpha * 28377)>>15;
    v->tmp3 = v->tmp2 - v->tmp1;

    v->vecSector = 3;
    v->vecSector = (v->tmp2>0)?(v->vecSector-1):v->vecSector;
    v->vecSector = (v->tmp3>0)?(v->vecSector-1):v->vecSector;
    v->vecSector = (v->tmp1<0)?(7-v->vecSector):v->vecSector;
	
	if(v->vecSector == 1 || v->vecSector == 4)
	{
		v->Ta= v->tmp2;
		v->Tb= v->tmp1-v->tmp3;
		v->Tc=-v->tmp2;
	}
	else if(v->vecSector == 2 || v->vecSector == 5)
	{
		v->Ta= v->tmp3+v->tmp2;
		v->Tb= v->tmp1;
		v->Tc=-v->tmp1;
	}
	else
	{
		v->Ta= v->tmp3;
		v->Tb=-v->tmp3;
		v->Tc=-(v->tmp1+v->tmp2);
	}
		
}
